/**
 * https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/
 * @param {string[]} tokens
 * @return {number}
 */

 const operators = ['+', '-', '*', '/'];

 function doOperate (l, r, o) {
     let ret;
     switch(o) {
         case '+':
             ret = l + r;
             break;
         case '-':
             ret = l - r;
             break;
         case '*':
             ret = l * r;
             break;
         case '/':
             ret = parseInt(l / r);
             break;
         default:
     }
     return ret;
 }
 
 var evalRPN = function(tokens) {
     const numStack = [];
     if (!tokens || !tokens.length) return 0;
     tokens.forEach(token => {
         if (operators.includes(token)) {
             const right = numStack.pop();
             const left = numStack.pop();
             numStack.push(doOperate(left, right, token));
         } else {
             numStack.push(token - 0);
         }
     });
     return numStack.pop();
 };